﻿using System;

using BLL;
using Model;
using Utility;

namespace EvaluationSystem
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                txtName.Focus();
                imgBtnLogin.Attributes.Add("onclick", "return Check();");
            }
        }

        protected void BtnLogin_Click(object sender, EventArgs e)
        {
            string username = txtName.Text.Trim().ToLower();
            string password = txtPwd.Text.Trim().ToLower();

            AdminUser adminUser = new AdminUser();
            adminUser.UserNm = username;
            adminUser.UserPw = password;
            
            AdminUserBLL  adminBll = new  AdminUserBLL ();
            if (adminBll.CheckLogin(adminUser))
            {
                if (!txtValidate.Text.ToUpper().Equals(Session["CheckCode"].ToString()))
                {
                    MessageBox.ShowAndRedirect(this, "您输入的验证码有误，请重新输入！", "Login.aspx");
                    return;
                }

                /*设置session变量username为用户名*/
                Session["username"] = username;
                Session["usertype"] = "S";
                Response.Redirect("~/System/EnterpriseUserList.aspx");
            }
            else
            {
                MessageBox.ShowAndRedirect(this, "您输入的用户名称或者密码有误，请重新输入！", "Login.aspx");
            }
        }
    }
}
